﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace mal.Web.Routing
{
    public class RouteElement : ConfigurationElement
    {
        [ConfigurationProperty("Name")]
        public string Name
        {
            get
            {
                return (string)this["Name"];
            }
            set
            {
                this["Name"] = value;
            }
        }

        [ConfigurationProperty("Uri")]
        public string Uri
        {
            get
            {
                return (string)this["Uri"];
            }
            set
            {
                this["Uri"] = value;
            }
        }

        [ConfigurationProperty("MappedUri")]
        public string MappedUri
        {
            get
            {
                return (string)this["MappedUri"];
            }
            set
            {
                this["MappedUri"] = value;
            }
        }

        [ConfigurationProperty("Defaults")]
        public RouteElementValueCollection Defaults
        {
            get
            {
                return (RouteElementValueCollection)this["Defaults"];
            }
            set
            {
                this["Defaults"] = value;
            }
        }

        [ConfigurationProperty("Constraints")]
        public RouteElementValueCollection Constraints
        {
            get
            {
                return (RouteElementValueCollection)this["Constraints"];
            }
            set
            {
                this["Constraints"] = value;
            }
        }
    }

    public class RouteElementValueCollection : ConfigurationElementCollection
    {

        protected override ConfigurationElement CreateNewElement()
        {
            return new RouteElementValue();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((RouteElementValue)element).Name;
        }
    }

    public class RouteElementValue : ConfigurationElement
    {
        [ConfigurationProperty("Name")]
        public string Name
        {
            get
            {
                return (string)this["Name"];
            }
            set
            {
                this["Name"] = value;
            }
        }

        [ConfigurationProperty("Value")]
        public string Value
        {
            get
            {
                return (string)this["Value"];
            }
            set
            {
                this["Value"] = value;
            }
        }
    }
}
